import 'package:flutter/material.dart';
import 'package:flutter_widgets/Others/other_list.dart';
import 'package:flutter_widgets/Widgets/widget_list.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final PageStorageBucket bucket = PageStorageBucket();
  final List<Widget> _pages = [WidgetsList(key:PageStorageKey('home')), OthersList(key:PageStorageKey('scene'))];
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    BottomNavigationBarItem barItem(
        String title, IconData iconData, bool isSelected) {
      return BottomNavigationBarItem(
        icon: Icon(
          iconData,
          color: isSelected ? Colors.blue : Colors.grey,
        ),
        title: Text(
          title,
          style: TextStyle(
            color: isSelected ? Colors.blue : Colors.black,
          ),
        ),
      );
    }

    return Scaffold(
      body: PageStorage(
          child: _pages[_currentIndex],
          bucket: bucket,
        ),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          barItem('widgets', Icons.home, _currentIndex == 0),
          barItem('others', Icons.home, _currentIndex == 1),
        ],
        currentIndex: _currentIndex,
        onTap: (int index) {
          if (index != _currentIndex) {
            setState(() {
              _currentIndex = index;
            });
          }
        },
        type: BottomNavigationBarType.fixed,
      ),
    );
  }
}
